package parser

import (
	"regexp"

	"aqielife.cn/spider/singleSpider/zhenai/model"
)

// <th><a href="http://album.zhenai.com/u/1494367164" target="_blank">爱心</a></th>
const cityRe = `<th><a href="(http://album.zhenai.com/u/[\d]+)"[^>]*>([^<]+)</a></th>`

// http://www.zhenai.com/zhenghun/anshun  城市
func ParseCity(contents []byte) model.ParseResult {
	re := regexp.MustCompile(cityRe)
	matches := re.FindAllSubmatch(contents, -1)

	result := model.ParseResult{}

	for _, m := range matches {
		name := string(m[:][2])
		result.Items = append(result.Items, "User "+string(name))
		result.Requests = append(result.Requests, model.Request{
			Url: string(m[:][1]),
			ParserFunc: func(contents []byte) model.ParseResult {
				return ParseProfile(contents, string(name))
			},
		})
	}
	return result
}
